#include "stdafx.h"
#include "Strings.h"
#include "ItemConfigurationWidget.h"
#include "ui_ItemConfiguration.h"
#include "ItemsGroup.h"
#include "ItemBrowserConfig.h"

ItemConfigurationWidget::ItemConfigurationWidget(QWidget *parent /*= 0*/)
    : _itemsGroup(ItemsGroup::Main)
{
    ui = new Ui::ItemConfigurationWidget();
    ui->setupUi(this);
}

ItemConfigurationWidget::~ItemConfigurationWidget()
{
    delete ui;
}

void ItemConfigurationWidget::setItemsGroup(ItemsGroup group)
{
    _itemsGroup = group;

    switch (_itemsGroup)
    {
    case ItemsGroup::Main:
        ui->checkBox->setText(tr("main items"));
        ui->numberEdit->setText("1");
        ui->numberEdit->setReadOnly(true);
        break;
    case ItemsGroup::Sub:
        ui->checkBox->setText(tr("sub-items"));
        break;
    case ItemsGroup::Compare:
        ui->checkBox->setText(tr("compare-items"));
        break;
    case ItemsGroup::Unknown:
        ui->checkBox->setText(tr("unknown-items"));
        break;
    default:
        break;
    }
}

ItemBrowserConfig ItemConfigurationWidget::toConfig() const
{
    ItemBrowserConfig config;
    config.group = this->_itemsGroup;
    config.enabled = ui->checkBox->isChecked();
    config.number = ui->numberEdit->text().toInt() ;
    config.interval = ui->intervalEdit->text().toInt() ;
    config.firstCapture = ui->firstCaptureCheckBox->isChecked() ;
    config.topCapture = ui->topCaptureCheckBox->isChecked() ;
    config.midCapture = ui->midCaptureCheckBox->isChecked() ;
    config.bottomCapture = ui->bottomCaptureCheckBox->isChecked() ;
    config.ratesCapture = ui->ratesCaptureCheckBox->isChecked() ;
    config.tradesCapture = ui->tradesCaptureCheckBox->isChecked();
    config.collectItemCapture = ui->collectCaptureCheckBox->isChecked();
    return config;
}

//QVariantMap ItemConfigurationWidget::toJsonObject() const
//{
//    return QVariantMap{
//        { "group", enTable.at(_itemsGroup) },
//        { "number", ui->numberEdit->text().toInt() },
//        { "interval", ui->intervalEdit->text().toInt() },
//        { "firstCapture", ui->firstCaptureCheckBox->isChecked() },
//        { "topCapture", ui->topCaptureCheckBox->isChecked() },
//        { "midCapture", ui->midCaptureCheckBox->isChecked() },
//        { "bottomCapture", ui->bottomCaptureCheckBox->isChecked() },
//        { "ratesCapture", ui->ratesCaptureCheckBox->isChecked() },
//        { "tradesCapture", ui->tradesCaptureCheckBox->isChecked() },
//        { "collectCapture", ui->collectCaptureCheckBox->isChecked() }
//    };
//}

